package dao;

import java.util.LinkedList;

import models.cards.ICard;
import models.cards.InfectionCityCard;
import models.cards.PlayerCityCard;
import models.decks.InfectionDeck;
import models.decks.PlayerDeck;
import models.game.Game;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class GameDAO 
{
	ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
	CityDAO cityDao = (CityDAO) context.getBean("cityDao");
	DiseaseDAO diseaseDao = (DiseaseDAO) context.getBean("diseaseDao");
	
	public void createGameObjects(Game game)
	{
		game.setDiseases(diseaseDao.getAllDiseases());
		game.setCities(cityDao.getAllCities(game.getDiseases()));
		createPlayerDeck(game);
		createInfectionDeck(game);
	}
	
	private void createPlayerDeck(Game game)
	{
		LinkedList<ICard> playerDeck = new LinkedList<ICard>();
		for (String s : game.getCities().keySet())
		{
			ICard card = new PlayerCityCard(game.getCities().get(s));
			playerDeck.add(card);
		}
		game.setPlayerDeck(new PlayerDeck(playerDeck));
	}
	
	private void createInfectionDeck(Game game)
	{
		LinkedList<ICard> infectionDeck = new LinkedList<ICard>();
		for (String s : game.getCities().keySet())
		{
			ICard card = new InfectionCityCard(game.getCities().get(s));
			infectionDeck.add(card);
		}
		game.setInfectionDeck(new InfectionDeck(infectionDeck));
	}
}
